package LeetCode.stack_queue;

import java.util.Stack;

public class NC_272 {
    public boolean IsPopOrder(int[] pushA, int[] popB) {
        Stack<Integer> stack = new Stack<>();
        int i, j = 0;
        for (i = 0; i < pushA.length; i++) {
            stack.push(pushA[i]);
            while (j < popB.length && !stack.empty() && stack.peek() == popB[j]) {
                stack.pop();
                j++;
            }
        }
        return stack.empty();
    }
}
